package org.his.controller.echart;

import org.apache.ibatis.annotations.Param;
import org.his.dao.CaiwuTongjiDao;
import org.his.pojo.tongji.CaiwuTongJi;
import org.his.pojo.tongji.GongZuoLiangTongJi;
import org.his.pojo.tongji.YaoPinXiaoShou;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/Echart")
@Scope("prototype")
public class Echartcontroller {
    @Autowired
    private CaiwuTongjiDao caiwuTongjiDao;

    /*财务统计*/
    @RequestMapping("caiwuEchart")
    @ResponseBody
    public Map<String,List<Object>> queryb(String datatime1,String datatime2,String moneyType) throws Exception{
        Map<String,List<Object>> map = new HashMap<>();

        List<CaiwuTongJi> list = caiwuTongjiDao.tongjicaiwu(datatime1,datatime2,moneyType);
        List<Object> moneyList = new ArrayList<>();
        List<Object> dataList = new ArrayList<>();

        for (CaiwuTongJi c: list) {
            moneyList.add(c.getMoney());
            dataList.add(c.getPayDate());
        }
        map.put("moneyList",moneyList);
        map.put("dataList",dataList);
        return map;
    }

    @RequestMapping("/caiwuindex")
    public String caiwuindex() throws Exception{
        return "tongji/caiwuindex";
    }

    @RequestMapping("/gongzuoliangindex")
    public String gongzuoliangindex() throws Exception{
        return "tongji/gongzuoliang";
    }


    @RequestMapping("/xiaoshou")
    public String xiaoshou() throws Exception{
        return "tongji/xiaoshou";
    }
    @RequestMapping("/tongji")
    public String tongji() throws Exception{
        return "tongji/tongji";
    }

    /*工作量统计*/
    @RequestMapping("/gongzuoliang")
    @ResponseBody
    public Map<String,List<Object>> gongzuoliang(@RequestParam(defaultValue = "1") String state)throws Exception{
        Map<String,List<Object>> map = new HashMap<>();

        List<GongZuoLiangTongJi> list = caiwuTongjiDao.tongjigongzuoliang(state);
        List<Object> countNum = new ArrayList<>();
        List<Object> username = new ArrayList<>();

        for (GongZuoLiangTongJi c: list) {
            countNum.add(c.getCountnum());
            username.add(c.getUsername());
        }
        map.put("countNum",countNum);
        map.put("username",username);
        return map;
    }

    /*药品销售前10名*/
    @RequestMapping("/Top")
    @ResponseBody
    public Map<String,List<Object>> Top(@RequestParam(defaultValue = "1") String state)throws Exception{
        Map<String,List<Object>> map = new HashMap<>();

        List<YaoPinXiaoShou> list = caiwuTongjiDao.yaopinxiaoshou(state);
        List<Object> countNum = new ArrayList<>();
        List<Object> username = new ArrayList<>();

        for (YaoPinXiaoShou c: list) {
            countNum.add(c.getCountNum());
            username.add(c.getYpname());
        }
        map.put("countNum",countNum);
        map.put("username",username);
        return map;
    }


}
